let arr = [2,4 ,7,3,1,6,5]


function quikSort(arr) {
    if (arr.length <= 1) {
        return arr
    }
    let middleIndex = Math.floor(arr.length/2)
    let middle = arr.splice(middleIndex,1)[0]
    let left = []
    let right = []
    const len =arr.length
    for (let i = 0; i < len; i++) {
        if (arr[i] < middle) {
            left.push(arr[i])
        }else{
            right.push(arr[i])
        }
    }
    return [...quikSort(left),middle,...quikSort(right)]
}

console.log(quikSort(arr));
